#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import List, Dict
from .base import FilterRule

class ContentLengthFilter(FilterRule):
    """内容长度过滤规则 - 筛除过短的内容"""
    
    def __init__(self, min_length: int = 5):
        """
        初始化内容长度过滤器
        
        Args:
            min_length: 最小字符数，默认为5
        """
        self.min_length = min_length
    
    def should_filter(self, add_content: str, remove_content: str, hunk_changes: List[Dict]) -> bool:
        """判断是否应该过滤（内容过短）"""
        # 清理内容，去除前后的空白字符
        add_clean = add_content.strip()
        remove_clean = remove_content.strip()
        
        # 对于modify类型，检查两个内容的总长度
        if add_clean and remove_clean:
            # 这是modify类型，检查总长度
            total_length = len(add_clean) + len(remove_clean)
            if total_length < self.min_length:
                return True
        else:
            # 对于add或delete类型，分别检查
            if add_clean and len(add_clean) < self.min_length:
                return True
            if remove_clean and len(remove_clean) < self.min_length:
                return True
        
        # 如果添加和删除内容都为空，也过滤
        if not add_clean and not remove_clean:
            return True
        
        return False
    
    def get_filter_reason(self) -> str:
        return f"content_too_short: min_length={self.min_length}" 